/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import entities.Restaurant;
import java.util.List;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;

/**
 *
 * @author Ahmet
 */
@ManagedBean
@SessionScoped
public class NewBean {
    
    @PersistenceContext 
    private EntityManager em;
    @Resource 
    private UserTransaction utx;  
    
    private List<Restaurant> restList; 
    private Restaurant selectedRest;  
    private Integer restId;
    private String keyword;
    
    public NewBean() {
    }

    public Integer getRestId() {
        return restId;
    }

    public void setRestId(Integer restId) {
        this.restId = restId;
        selectedRest = (Restaurant) em.createNamedQuery("Restaurant.findByRid").setParameter("rid", restId).getSingleResult();
    }

    public Restaurant getSelectedRest() {
        return selectedRest;
    }

    public void setSelectedRest(Restaurant selectedRest) {
        this.selectedRest = selectedRest;
    }
    
    public void findRestaurants() {
        restList = (List<Restaurant>) em.createNamedQuery("Restaurant.findByKeyword").setParameter("keyword", keyword).getResultList();
    }

    public List<Restaurant> getRestList() {
        return restList;
    }

    public void setRestList(List<Restaurant> restList) {
        this.restList = restList;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
    
    public void refresh(){
        this.keyword = null;
        this.selectedRest=null;
        this.restId=null;
        //restList = null;
    }
    
}
